/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:何人亮
 * Date:2024-07-26
 * 15:18
 */
public class BubbleSort {
    public static void bubbleSort(int[] array){
        for(int i=0;i<array.length;i++){
            for (int j = 0; j < array.length-1-i; j++) {
                if(array[j]>array[j+1]){
                    int tem=array[j]    ;
                    array[j]=array[j+1];
                    array[j+1]=tem;
                }
            }
        }
    }
    public static void bubbleSortPerfect(int[] array){//优化后的冒泡排序
        for(int i=0;i<array.length;i++){
            boolean flg=false;//设置标志位
            for (int j = 0; j < array.length-1-i; j++) {
                if(array[j]>array[j+1]){
                    int tem=array[j]    ;
                    array[j]=array[j+1];
                    array[j+1]=tem;
                    flg=true;
                }
            }
            if(!flg){
                break;
            }
        }
    }
}
